package com.yyk.yiliao.adapter.anzhengzhaoyao;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yyk.yiliao.R;
import com.yyk.yiliao.bean.StoreCustomclass_Info;
import com.yyk.yiliao.util.rx.ApiService;

import java.util.List;


/**
 * Created by ${zk} on 2018/8/22 0022.
 * <p>
 * 按症找药 的 适配器
 */

public class MyGridViewAdapter extends BaseAdapter {
    private Context context;
    private List<StoreCustomclass_Info.DataBean> list2;

    public MyGridViewAdapter(Context context, List<StoreCustomclass_Info.DataBean> list2) {
        this.context = context;
        this.list2 = list2;
    }

    @Override
    public int getCount() {
        return list2.size();
    }

    @Override
    public Object getItem(int position) {
        return list2.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_azzy_gridview_tv_img2, null);
            holder = new ViewHolder(convertView);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv.setText(list2.get(position).getName() + "");
        Glide.with(context).load(ApiService.BASE_URL + list2.get(position).getIcon()).into(holder.img);
        return convertView;
    }

    class ViewHolder {
        TextView tv;
        ImageView img;

        public ViewHolder(View view) {
            tv = view.findViewById(R.id.tv);
            img = view.findViewById(R.id.img);
        }
    }
}